package com.huanling.main;

import javafx.application.Application;
import javafx.fxml.FXMLLoader;
import javafx.scene.Scene;
import javafx.scene.control.CheckBoxTreeItem;
import javafx.scene.control.TreeView;
import javafx.scene.control.cell.CheckBoxTreeCell;
import javafx.scene.layout.GridPane;
import javafx.stage.Stage;

import java.util.Objects;

/**
 * 主界面启动类 --- View
 *
 * @author guibosun
 */
public class MainApp extends Application {

    public static Stage primaryStage;

    public static final TreeView<String> EQUALS_GENERATE = new TreeView<>();

    public static final TreeView<String> KEY_GENERATE = new TreeView<>();

    public static void main(String[] args) {
        launch(args);
    }

    @Override
    public void start(Stage primaryStage) throws Exception {
        MainApp.primaryStage = primaryStage;
        GridPane root = FXMLLoader.load(Objects.requireNonNull(getClass().getClassLoader().getResource("Main.fxml")));
        addTreeView(root);
        Scene scene = new Scene(root, 600, 500);

        primaryStage.setTitle("Data Checker");
        primaryStage.setScene(scene);
        primaryStage.show();
    }

    private void addTreeView(GridPane root) {
        CheckBoxTreeItem<String> keyRootItem = new CheckBoxTreeItem<>("参照列");
        keyRootItem.setExpanded(true);

        KEY_GENERATE.setCellFactory(CheckBoxTreeCell.forTreeView());
        KEY_GENERATE.setEditable(true);
        KEY_GENERATE.setRoot(keyRootItem);
        KEY_GENERATE.prefHeight(30);
        KEY_GENERATE.prefWidth(224.0);

        CheckBoxTreeItem<String> equalsTreeRootItem = new CheckBoxTreeItem<>("对比列");
        equalsTreeRootItem.setExpanded(true);

        EQUALS_GENERATE.setCellFactory(CheckBoxTreeCell.forTreeView());
        EQUALS_GENERATE.setEditable(true);
        EQUALS_GENERATE.setRoot(equalsTreeRootItem);
        EQUALS_GENERATE.prefHeight(30);
        EQUALS_GENERATE.prefWidth(224.0);
        root.add(KEY_GENERATE, 7, 13);
        root.add(EQUALS_GENERATE, 9, 13);
    }
}